<?php

namespace App\Http\Controllers\Reservation;

use App\Http\Controllers\Controller;
use App\Models\Hospital;
use App\Models\Patient;
use App\Models\Reservation\Ability;
use App\Project\Traits\DoctorAndHospitalLinkage;
use App\Models\SceneManage;
use Illuminate\Support\Facades\DB;
use App\Models\Reservation\Schedule;

class IndexController extends Controller
{

    protected $hospitalManage;
    use DoctorAndHospitalLinkage;


    public function index()
    {
        $user = \Auth::user();

        $linkage = $this->linkageWithAnAbility('reservation');

        return view('reservation.index', array_merge(
                compact('user'), $linkage
        ));
    }

    /**
     * Show the form for creating a new resource.
     * @param $patient
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function create(Patient $patient)
    {
        $user = \Auth::user();

        $current_hospital = $user->hospital;

        $linkage = $this->linkageWithAnAbility('reservation');

        return view('reservation.add', array_merge(
                compact('user', 'patient', 'current_hospital'), $linkage
        ));
    }

    public function manage()
    {
        $user = \Auth::user();

        if ($user->isAn('admin')) {
            $hospitals = Ability::find(1)->hospitals;
        } else {
            $hospitals = $user->hospital;
        }

        return view('reservation.management', compact('user', 'hospitals'));
    }
}
